using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;

public class UILevelChild : ScrollChildBase {
    public Text levelName;
    string fileName;
    public InputField toLevelInput;
    public GameObject changId;
    public Text fromLevelText;
    public override void init (int index, ScrollTool scrollTool) {
        base.init (index, scrollTool);
        refresh ();
    }
    public override void refresh () {
        fileName = Global.GameProxy.getNameByIndex (index);
        string name = fileName.Replace (".json", "");
        levelName.text = name;
    }
    //点击事件
    public override void _onClick (string btnTag, GameObject obj) {
        base._onClick (btnTag, obj);
        switch (btnTag) {
            case "delete":
                Global.GameProxy.RemoveFile (fileName);
                Global.GameProxy.setData ();
                break;
            case "changeId":
                fromLevelText.text = Global.GameProxy.GetLevelByFileName (fileName).ToString ();
                changId.SetActive (true);
                break;
            case "saveChangeId":
                int fromLevel = Global.GameProxy.GetLevelByFileName (fileName);
                int toLevel = int.Parse (toLevelInput.text);
                Global.GameProxy.reNameFile (fromLevel, toLevel);
                changId.SetActive (false);
                Global.GameProxy.setData ();
                break;
            case "enter":
                Global.GameProxy.ControlBox.enter(index);
                break;
            default:
                Debug.Log ("点击了" + btnTag + "未处理");
                break;
        }
    }
}